function ModuleImageNumber() {
  this._container = null;
}

ModuleImageNumber.prototype._open = function(container, options) {
  var table, tr, td, _self = this;
  this._container = container;
  
  this._idx = (options && options.idx) ? options.idx : 0;
  this._numbers = options.numbers;
  this._back = options.back;
  this._obj = options.obj;
  this._nums = options.nums;
  this._urls = options.urls;
  this._exist = options.exist;
  this._callback = options.callback;

//  this._position = (options && options.pos) ? options.pos : [((document.body.offsetWidth / 2) - 50), ((document.body.offsetHeight / 2) - 50)];
//  var num = (options && options.num) ? options.num : 1;
  this._gui = new ImageNumber(document, this._container, options.width, options.height, null, null, options)._gui;
  
  if (this._exist) {
    for (index in this._urls) {
      this._gui.move[index].style.border = 'solid 1px #333';
      this._gui.move[index].style.position = 'absolute';
      this._gui.move[index].style.top = this._obj.top + 'px';
      this._gui.move[index].style.left = (parseInt(this._obj.left) + parseInt(index * 30)) + 'px';
      this._gui.move[index].style.width = this._obj.width + 'px';
      this._gui.move[index].style.height = this._obj.height + 'px';
      this._gui.move[index].style.backgroundImage = 'url(' + this._urls[index] + ')';
      
      this._gui.close[index].style.display = 'inline';
      this._gui.close[index].onclick = function() { new RequestUtils()._write(JSON.stringify([{ n: 'pz_tnfc_ivq_number', a: [], r: [_self._obj] }]), function(result, params) { location.href = '?t=test&i=' + _self._idx; }, { pos: DOMUtils.findPos(this) });
                                                  };
    }
    
  } else {
    
    this._gui.number.value = this._obj.number;
    
    this._gui.move.style.border = 'solid 1px #333';
    this._gui.move.style.position = 'absolute';
    this._gui.move.style.top = this._obj.top + 'px';
    this._gui.move.style.left = this._obj.left + 'px';
    this._gui.move.style.width = this._obj.width + 'px';
    this._gui.move.style.height = this._obj.height + 'px';
    
    this._gui.content.style.top = (parseInt(8) + parseInt(this._gui.move.style.top.split('px')[0]) + parseInt(this._gui.move.style.height.split('px')[0])) + 'px';
    this._gui.content.style.left = this._gui.move.style.left;
    
    this._gui.save.onclick = function() { _self._obj.width = parseInt(_self._gui.move.style.width.split('px')[0]);
                                          _self._obj.height = parseInt(_self._gui.move.style.height.split('px')[0]);
                                          _self._obj.top = parseInt(_self._gui.move.style.top.split('px')[0]);
                                          _self._obj.left = parseInt(_self._gui.move.style.left.split('px')[0]);
                                          _self._obj.number = _self._gui.number.value;
                                          new RequestUtils()._write(JSON.stringify([{ n: 'pz_tnfc_ivq_number', a: [_self._obj], r: [] }]), function(result, params) { location.href = '?t=test&i=' + _self._idx; }, { pos: DOMUtils.findPos(this) });
                                        };
                                        
    this._gui.close._num = this._obj.number;
    this._gui.close.onclick = function() { _self._close();
                                           for (num in _self._nums) {
                                             if (_self._nums[num] == this._num) {
                                               _self._nums.splice(num, 1);
                                             }
                                           }
                                           MiscUtils.remove(_self._numbers, _self._obj, 'track_id');
                                           _self._callback(_self._nums);
                                         };
    
    this._moveX = 0;
    this._moveY = 0;
    this._moveTop = 0;
    this._moveLeft = 0;
    this._moveable = false;
    this._docMouseMoveEvent = document.onmousemove;
    this._docMouseUpEvent = document.onmouseup;
    this._iWidth = 696;
    this._iHeight = 241;
    this._width = 30;
    this._height = 30;
  
    this._gui.move.onmouseover = function() { this.className = 'popupMove'; };
    this._gui.move.onmousedown = function() { var evt = _self._getEvent();
                                              _self._moveable = true;
                                              _self._moveX = evt.clientX;
                                              _self._moveY = evt.clientY;
                                              _self._moveTop = parseInt(this.style.top);
                                              _self._moveLeft = parseInt(this.style.left);
                                            };
    this._gui.move.onmousemove = function() { if (_self._moveable) {
                                                this.className = 'popupMove';
                                                var evt = _self._getEvent();
                                                var x = parseInt(_self._moveLeft) + parseInt(evt.clientX) - parseInt(_self._moveX);
                                                var y = parseInt(_self._moveTop) + parseInt(evt.clientY) - parseInt(_self._moveY);
                                                if ( x > 0 && ( x + _self._width < _self._iWidth) && y > 0 && (y + _self._height < _self._iHeight) ) {
                                                  this.style.left = x + "px";
                                                  this.style.top = y + "px";
                                                }
                                                _self._gui.content.style.top = (parseInt(8) + parseInt(_self._gui.move.style.top.split('px')[0]) + parseInt(_self._gui.move.style.height.split('px')[0])) + 'px';
                                                _self._gui.content.style.left = _self._gui.move.style.left;
                                              }
                                            };
    this._gui.move.onmouseup = function () { if (_self._moveable) {
                                               document.onmousemove = _self._docMouseMoveEvent;
                                               document.onmouseup = _self._docMouseUpEvent;
                                               _self._moveable = false;
                                               _self._moveX = 0;
                                               _self._moveY = 0;
                                               _self._moveTop = 0;
                                               _self._moveLeft = 0;
                                               this.className = 'popupUp';
                                             }
                                           };
    
    this._back.onmousemove = function() { if (_self._moveable) {
                                            var evt = _self._getEvent();
                                            var x = parseInt(_self._moveLeft) + parseInt(evt.clientX) - parseInt(_self._moveX);
                                            var y = parseInt(_self._moveTop) + parseInt(evt.clientY) - parseInt(_self._moveY);
                                            if ( x > 0 && ( x + _self._width < _self._iWidth) && y > 0 && (y + _self._height < _self._iHeight) ) {
                                              _self._gui.move.style.left = x + "px";
                                              _self._gui.move.style.top = y + "px";
                                            }
                                            _self._gui.content.style.top = (parseInt(8) + parseInt(_self._gui.move.style.top.split('px')[0]) + parseInt(_self._gui.move.style.height.split('px')[0])) + 'px';
                                            _self._gui.content.style.left = _self._gui.move.style.left;
                                          }
                                        };
    
    this._back.onmouseup = function () { if (_self._moveable) {
                                           document.onmousemove = _self._docMouseMoveEvent;
                                           document.onmouseup = _self._docMouseUpEvent;
                                           _self._moveable = false;
                                           _self._moveX = 0;
                                           _self._moveY = 0;
                                           _self._moveTop = 0;
                                           _self._moveLeft = 0;
                                         }
                                       };
  }
};

ModuleImageNumber.prototype._close = function() {
  if (this._back) {
    this._container.removeChild(this._gui.move);
    this._container.removeChild(this._gui.content);
    this._container = null;
  }
};

ModuleImageNumber.prototype._getEvent = function() {
  if(window.parent == window) {
    return window.event || arguments.callee.caller.arguments[0];
  } else {
    return window.parent.event || arguments.callee.caller.arguments[0];
  }
};